package com.elinkway.infinitemovies.view;


import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.Lottery;
import com.elinkway.infinitemovies.ui.activity.SpreadActivity;
import com.elinkway.infinitemovies.utils.UIs;
import com.le123.ysdq.R;


public class LotteDialog {

    private AlertDialog dialog;

    public void show(Context context, final Lottery lottery) {
        View v =
                UIs.inflate(context, R.layout.lottery_dialog_layout, null);
        TextView contentText = (TextView) v.findViewById(R.id.lottery_desc);
        TextView positiveBtn = (TextView)v.findViewById(R.id.lottery_positive_button);
        TextView negativeBtn = (TextView)v.findViewById(R.id.lottery_negative_button);
        contentText.setText(lottery.getPopWinInfo().getMessage());
        positiveBtn.setText(lottery.getPopWinInfo().getPositiveText());
        negativeBtn.setText(lottery.getPopWinInfo().getNegativeText());
        dialog = new Builder(new ContextThemeWrapper(context, R.style.lottery_dialog)).create();
        dialog.show();
        dialog.setContentView(v);
        dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        dialog.getWindow().setGravity(Gravity.CENTER);
        positiveBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(dialog.getContext(), SpreadActivity.class);
                i.putExtra("lottery", lottery);
                dialog.getContext().startActivity(i);
                dialog.dismiss();
            }
        });
        negativeBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    public boolean isShow() {

        return null != dialog && dialog.isShowing();
    }

    public void cancel() {
        dialog.cancel();
    }
}
